package com.wdb007.venus.svc.biz.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtil {

	public static Date now() {
		return new Date();
	}
	/**
	 * 获取两者时间差，多少天多少小时多少分钟
	 * @param endDate
	 * @param nowDate
	 * @return
	 */
	public static String getDatePoor(Date endDate, Date nowDate) {
		 
	    long nd = 1000 * 24 * 60 * 60;
	    long nh = 1000 * 60 * 60;
	    long nm = 1000 * 60;
	    // long ns = 1000;
	    // 获得两个时间的毫秒时间差异
	    long diff = endDate.getTime() - nowDate.getTime();
	    // 计算差多少天
	    long day = diff / nd;
	    // 计算差多少小时
	    long hour = diff % nd / nh;
	    // 计算差多少分钟
	    long min = diff % nd % nh / nm + (diff % nd % nh % nm > 0 ? 1 : 0);
	    // 计算差多少秒//输出结果
	    // long sec = diff % nd % nh % nm / ns;
	    StringBuffer result = new StringBuffer();
	    if(day != 0)  
	    	result.append(day).append("天");
	    if(hour != 0) 
	    	result.append(hour).append("小时");
	    if(day == 0 && hour == 0 && min > 5) 
	    	result = new StringBuffer("不足1小时");
	    if(day == 0 && hour == 0 && min <= 5) 
	    	result = new StringBuffer("不足5分钟");
	    if(day != 0 && hour == 0 && min > 0) {
	    	result.append(1).append("小时");
	    }
	    return result.toString() ;
	}
	
	public static void main(String[] args) throws ParseException {
//		String start = "2018-10-02 14:57:35";
//		String end = "2017-12-09 13:29:13";
//		DateFormat df =new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//		Date startDate = df.parse(start);
//		Date endDate = df.parse(end);
//		System.out.println(getMonths(startDate, endDate));
		System.out.println(getNextMouth(new Date()));
//		System.out.println(getNextYear(new Date()));
	}
	
	public static Date getNextMouth(Date now) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(now);
		calendar.add(Calendar.DAY_OF_YEAR, 30);
		return calendar.getTime();
	}
	
	public static Date getNextYear(Date now) {
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(now);
		calendar.add(Calendar.YEAR, 1);
		return calendar.getTime();
	}
	
	public  static int getMonths(Date date1, Date date2){     
       int iMonth = 0;     
       int flag = 0;     
       try{     
           Calendar minCalendar = Calendar.getInstance();     
           minCalendar.setTime(date1);     
    
           Calendar maxCalendar = Calendar.getInstance();     
           maxCalendar.setTime(date2);     
    
           if (maxCalendar.equals(minCalendar))     
               return 0;     
           if (minCalendar.after(maxCalendar)){     
              return -1;
           }     
           if (maxCalendar.get(Calendar.DAY_OF_MONTH) < minCalendar.get(Calendar.DAY_OF_MONTH))     
               flag = 1;     
    
           if (maxCalendar.get(Calendar.YEAR) > minCalendar.get(Calendar.YEAR))     
               iMonth = ((maxCalendar.get(Calendar.YEAR) - minCalendar.get(Calendar.YEAR))     
                       * 12 + maxCalendar.get(Calendar.MONTH) - flag)     
                       - minCalendar.get(Calendar.MONTH);     
           else    
               iMonth = maxCalendar.get(Calendar.MONTH)     
                       - minCalendar.get(Calendar.MONTH) - flag;     
    
       } catch (Exception e){     
        e.printStackTrace();     
       }     
       return iMonth;     
   }    
}
